﻿$(function () {
    $("#isPass").change(function () {
        var val = $(this).val();
        if (val == 0) {
            $("#divNotPassMessage").css("display", "block");
        } else {
            $("#divNotPassMessage").css("display", "none");
        }
    });

    //限制键盘只能按数字键、小键盘数字键、退格键
    $(".txt-digits").keydown(function (e) {
        var code = parseInt(e.keyCode);
        if (code >= 96 && code <= 105 || code >= 48 && code <= 57 || code == 8 || code == 110) {
            return true;
        } else {
            return false;
        }
    });

    //文本框输入事件,任何非正整数的输入都重置为1
    $(".txt-digits").bind("input propertychange", function () {
        if (isNaN(parseFloat($(this).val())) || parseFloat($(this).val()) < 0) $(this).val("");
    });
});

var admin = {
    //删除提交
    Del: function (url, Search, tableName) {
        var select;
        //console.log(tableName)
        if (tableName != "" && tableName != undefined) {
            //console.log("1")
            select = $("#" + tableName).bootstrapTable('getSelections');
        } else {
            //console.log("2")
            select = $table.bootstrapTable('getSelections');
        }
        if (select.length) {
            var id = select[0].id;
            layer.confirm('确定要删除？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.post(url, { id: id.toString() }, function (result) {
                    var icon = 1;
                    if (result.resultCode == 1000) {
                        Search();
                    } else {
                        icon = 2;
                    }
                    layer.msg(result.message, {
                        icon: icon,
                        time: 1500
                    });
                });
            });

        } else {
            layer.msg("请选择要删除的项！", {
                icon: 2,
                time: 1500
            });
        }
    },
    //批量删除提交
    Dels: function (url, Search) {
        var select = $table.bootstrapTable('getSelections');
        if (select.length) {
            var ids = new Array();
            $.each(select, function (index, item) {
                ids.push(item.Id);
            });
            layer.confirm('确定要删除？', {
                btn: ['删除', '取消'] //按钮
            }, function () {
                $.post(url, { ids: ids.toString() }, function (result) {
                    var icon = 1;
                    if (result.resultCode == 1000) {
                        Search();
                    } else {
                        icon = 2;
                    }
                    layer.msg(result.message, {
                        icon: icon,
                        time: 1500
                    });
                });
            });

        } else {
            layer.msg("请选择要删除的项！", {
                icon: 2,
                time: 1500
            });
        }
    },
    //添加
    AddSubmit: function (backurl) {
        if ($("#form_ff_validation").valid()) {
            var url = $("#form_ff_validation").attr("action");
            $.ajax({
                url: url,
                data: $("#form_ff_validation").serialize(),
                type: "POST",
                success: function (result) {
                    if (result.resultCode == 1000) {
                        layer.msg(result.message, {
                            icon: 1,
                            time: 1500
                        }, function () {
                            if (backurl != '') {
                                location.href = backurl;
                            }
                            
                        });
                    } else {
                        layer.open({
                            content: result.message
                        });
                    }
                }
            });
        }
    },
    //请求删除
    Remove: function Remove(id, url, Search) {
        layer.confirm('确定要请求删除？', {
            btn: ['提交', '取消'] //按钮
        }, function () {
            $.post(url, { id: id }, function (result) {
                var icon = 1;
                if (result.resultCode == 1000) {
                    Search();
                } else {
                    icon = 2;
                }
                layer.msg(result.message, {
                    icon: icon,
                    time: 1500
                });
            });
        });
    },
 
};



Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    fmt = fmt || "yyyy-MM-dd";
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function ymdDateFormatter(value, row, index) {
    if (value) {
        try {
            return eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)")).format('yyyy-MM-dd');
        }catch(ex){
            return "";
        }
    }
}

function ymdhmsDateFormatter(value, row, index) {
    if (value) {
        try {
            return eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)")).format('yyyy-MM-dd hh:mm:ss');
        } catch (ex) {
            return "";
        }
    }
}

function hmsDateFormatter(value, row, index) {
    if (value) {
        try {
            var h = value.Hours < 10 ? "0" + value.Hours : value.Hours;
            var m = value.Minutes < 10 ? "0" + value.Minutes : value.Minutes;
            var s = value.Seconds < 10 ? "0" + value.Seconds : value.Seconds;
            return h + ":" + m + ":" + s;
        } catch (ex) {
            return "";
        }
    }
}

function enableFormatter(value, row, index) {
    if (value == true) {
        return "启用";
    } else {
        return "禁用";
    }
}

function openFormatter(value, row, index) {
    if (value == 1) {
        return "启用";
    } else {
        return "禁用";
    }
}

function ynFormatter(value, row, index) {
    if (value == true) {
        return "是";
    } else {
        return "不是";
    }
}

function yn2Formatter(value, row, index) {
    if (value == 1) {
        return "是";
    } else {
        return "不是";
    }
}

function auditFormatter(value, row, index) {
    if (value == 1) {
        return "审核";
    } else if (value == 2) {
        return "审核中"
    } else if (value == 3) {
        return "审核不通过"
    } else {
        return "";
    }
}